package com.zzk.lanouhn.myapplication1.adapters;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.jude.rollviewpager.adapter.StaticPagerAdapter;
import com.squareup.picasso.Picasso;
import com.zzk.lanouhn.myapplication1.activity.InvestOneDetailed;
import com.zzk.lanouhn.myapplication1.modles.InvestOneLunBoModle;

/**
 * 轮播图的适配器
 * Created by lanouhn on 16/8/26.
 */
public class TestNormalAdaptert extends StaticPagerAdapter {

    private Context mContext;
    private InvestOneLunBoModle lunBoModle;

    public TestNormalAdaptert(Context mContext, InvestOneLunBoModle lunBoModle) {
        this.mContext = mContext;
        this.lunBoModle = lunBoModle;
    }

    @Override
    public View getView(ViewGroup container, final int position) {
        ImageView view = new ImageView(container.getContext());
        Picasso.with(mContext).load(lunBoModle.getData().get(position).getPic_ad_url()).into(view);
        view.setScaleType(ImageView.ScaleType.CENTER_CROP);
        view.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));

        if (position!=0){
            view.setOnClickListener(new View.OnClickListener() {
                //点击事件
                @Override
                public void onClick(View v) {
                    String s = lunBoModle.getData().get(position).getGoto_param().getItemid();
                    Intent intent=new Intent(mContext, InvestOneDetailed.class);
                    intent.putExtra("lunbo",s);
                    mContext.startActivity(intent);
                }
            });
        }else {
            view.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    String ss=lunBoModle.getData().get(position).getId();
                    Intent intents=new Intent(mContext,InvestOneDetailed.class);
                    intents.putExtra("lunboShu",ss);
                    mContext.startActivity(intents);
                }
            });
        }
        return view;
    }

    @Override
    public int getCount() {
        return lunBoModle.getData().size();
    }
}
